#include <iostream>
#include "forward_list.h"
using namespace std;

int main()
{
	{
		forward_list<int> l;
		for (int i = 0; i < 10; i++)
		{
			l.push_front(i);
		}

		forward_list<int> l2(l);
		forward_list<int>::iterator it2 = l2.begin();
		cout << "Copyconstructor: " << endl;
		for (auto it = l.begin(); it != l.end(); it++)
		{
			cout << it->data << ", " << it2->data << endl;
			if (it->data != it2->data)
			{
				throw exception("hej");
			}
			it2++;
		}
		forward_list<int> l3;
		int a = 54;
		l3.push_front(a);
		l3 = l;

		forward_list<int>::iterator it3 = l3.begin();
		cout << "\nCopyassignment: " << endl;
		for (auto it = l.begin(); it != l.end(); it++)
		{
			cout << it->data << ", " << it3->data << endl;
			if (it->data != it3->data)
			{
				throw exception("hej");
			}
			it3++;
		}
	}
	
	{
		cout << "\nInsert_after: " << endl;
		forward_list<int> l4;
		int i1 = 1, i2 = 2, i3 = 4;
		l4.push_front(i1);
		l4.push_front(i2);
		l4.push_front(i3);
		for (auto it = l4.begin(); it != l4.end(); it++)
		{
			if (it->data == 4)
			{
				int i4 = 3;
				l4.insert_after(it, i4);
			}
		}
		for (auto it = l4.begin(); it != l4.end(); it++)
		{
			cout << it->data << endl;
		}
	}

	cout << "\nswap: " << endl;
	{
		forward_list<int> list;
		for (int i = 0; i < 5; i++)
		{
			list.push_front(i);
		}
		forward_list<int> list2;
		for (int i = 10; i < 40; i += 10)
		{
			list2.push_front(i);
		}
		list.print();
		list2.print();
		cout << endl;
		list.swap(list2);
		list.print();
		list2.print();

	}

	{
		forward_list<int> l;
		int i1 = 1, i2 = 10, i3 = 2;
		l.push_front(i1);
		l.push_front(i2);
		l.push_front(i3);
		l.erase(10);
		int i = 2;
		for (auto it = l.begin(); it != l.end(); it++)
		{
			if (i != it->data)
				throw exception("helvete");
			i--;
		}
	}
	{
		forward_list<int> l;
		int i1 = 1, i2 = 3, i3 = 2;
		l.push_front(i1);
		l.push_front(i2);
		l.push_front(i3);
		l.sort();
		int i = 1;
		for (auto it = l.begin(); it != l.end(); it++)
		{
			if (i != it->data)
				throw exception("fan");
			i++;
		}
	}

	system("pause");
	return 0;
}